asm
  ld sp,$A7FF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"

dim eee as uinteger at $A010
dim seed as uinteger at $A012
dim ee0 as uinteger at $A014
dim ee1 as uinteger at $A016
dim ee2 as uinteger at $A018
dim ee3 as uinteger at $A01A
dim ex0 as uinteger at $A01C
dim ey0 as uinteger at $A01E


sub mrjongputchar(txp1 as uinteger,typ1 as uinteger,tch1 as ubyte,tat1 as ubyte):
  poke $E040+txp1*32+typ1 bxor 31,tch1
  poke $E440+txp1*32+typ1 bxor 31,tat1
  end sub

'sub mrjongputsprite(tly2 as uinteger,txp2 as ubyte,typ2 as ubyte,tid2 as ubyte,tat1 as ubyte):
'  end sub




for ee0=0 to 31
  for ee1=0 to 31
    ee2=seed:seed=smsrnd(seed)
    ee2=seed:seed=smsrnd(seed)
    mrjongputchar(ee1,ee0,seed band 3,ee2 band 15)
    'pacmandelay(1000)
    next:next

for ee0=0 to 15
  for ee1=0 to 15
    mrjongputchar(ee1+11,ee0+13,ee0*16+ee1,0)
    'pacmandelay(1000)
    next:next

eee=0:ex0=8:ey0=8
do

mrjongputchar(1,1,48+((int(eee/10000)) mod 10),0)
mrjongputchar(2,1,48+((int(eee/1000)) mod 10),0)
mrjongputchar(3,1,48+((int(eee/100)) mod 10),0)
mrjongputchar(4,1,48+((int(eee/10)) mod 10),0)
mrjongputchar(5,1,48+(eee mod 10),0)

ee0=in($00) band $3F
mrjongputchar(3,3,48+((int(ee0/100)) mod 10),0)
mrjongputchar(4,3,48+((int(ee0/10)) mod 10),0)
mrjongputchar(5,3,48+(ee0 mod 10),0)

ee0=in($01)
mrjongputchar(3,4,48+((int(ee0/100)) mod 10),0)
mrjongputchar(4,4,48+((int(ee0/10)) mod 10),0)
mrjongputchar(5,4,48+(ee0 mod 10),0)

ex0=ex0+((ee0 band 4)/4)-((ee0 band 2)/2)
ey0=ey0+((ee0 band 8)/8)-((ee0 band 1)/1)
mrjongputchar(ex0,ey0,eee,0)

ee0=in($02)
mrjongputchar(3,5,48+((int(ee0/100)) mod 10),0)
mrjongputchar(4,5,48+((int(ee0/10)) mod 10),0)
mrjongputchar(5,5,48+(ee0 mod 10),0)


eee=eee+1
loop

do:loop







do
for eee=$040 to $3FF
  seed=smsrnd(seed)
  poke $E000+eee,seed
  seed=smsrnd(seed)
  poke $E400+eee,seed
  pacmandelay(1000)
  next

loop

do:loop






do
for eee=$E000 to $E7FF
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(1000)
  next

loop

do:loop


'static ADDRESS_MAP_START( mrjong_map, AS_PROGRAM, 8, mrjong_state )
'AM_RANGE(0x0000, 0x7fff) AM_ROM
'AM_RANGE(0x8000, 0x87ff) AM_RAM
'AM_RANGE(0xa000, 0xa7ff) AM_RAM
'AM_RANGE(0xe000, 0xe3ff) AM_RAM_WRITE(mrjong_videoram_w) AM_SHARE("videoram")
'AM_RANGE(0xe400, 0xe7ff) AM_RAM_WRITE(mrjong_colorram_w) AM_SHARE("colorram")
'ADDRESS_MAP_END

'static ADDRESS_MAP_START( mrjong_io_map, AS_IO, 8, mrjong_state )
'ADDRESS_MAP_GLOBAL_MASK(0xff)
'AM_RANGE(0x00, 0x00) AM_READ_PORT("P2") AM_WRITE(mrjong_flipscreen_w)
'AM_RANGE(0x01, 0x01) AM_READ_PORT("P1") AM_DEVWRITE("sn1", sn76489_device, write)
'AM_RANGE(0x02, 0x02) AM_READ_PORT("DSW") AM_DEVWRITE("sn2", sn76489_device, write)
'AM_RANGE(0x03, 0x03) AM_READ(io_0x03_r)     // Unknown
'ADDRESS_MAP_END



'
'sub pingpongputsprite(tlayer as ubyte,tx as ubyte,ty as ubyte,tid as ubyte,tclut as ubyte):
'  poke $9006+((tlayer band 15)*4),tx  '- x sprite 0
'  poke $9004+((tlayer band 15)*4),ty bxor 255  '- y sprite 0
'  poke $9005+((tlayer band 15)*4),tid          '- shape sprite 0
'  poke $9003+((tlayer band 15)*4),tclut        '- clut? sprite 0
'  end sub
'
'function test1(t1 as uinteger,t2 as uinteger,t3 as uinteger,t4 as uinteger)  as uinteger
'  end function
'
'sub zpoke(t1 as uinteger,t2 as ubyte)
'  poke t1,t2
'  end sub
'
'sub putchar(tx1 as uinteger, ty1 as uinteger, tch1 as uinteger)
'  poke ($8400+(tx1*32)+ty1) bxor %0000001111100000,(tch1 band 255)
'  end sub
'
'pingpongputsprite(0,21,10,4,3)
'pingpongputsprite(1,21,30,4,3)
'pingpongputsprite(2,21,50,4,3)
'pingpongputsprite(3,21,70,4,3)
'pingpongputsprite(4,21,90,4,3)
'pingpongputsprite(5,21,110,4,3)
'pingpongputsprite(6,21,130,4,3)
'pingpongputsprite(7,21,150,4,3)
'
'seed=0
'
'for ee2=64 to 1023-64
'  for ee3=1 to 100
'    poke $8400+ee2,$01
'    next:next
'
'ee4=0
'for ee2=3 to 3+15
'  for ee3=15 to 15+15
'    poke $8400+ee3+(ee2*32),ee4
'    ee4=ee4+1
'    next:next
'
'ee4=0
'for ee2=20 to 20+7
'  for ee3=15 to 15+15
'    poke $8400+ee3+(ee2*32),ee4 band 3
'    poke $8000+ee3+(ee2*32),int(ee4/4)
'    ee4=ee4+1
'    next:next
'
'
'
'
'for ee2=4 to 7
'  for ee3=2 to 5
'    poke $8400+ee3+(ee2*32),code("X")
'    next
'    next
'
'test1(377,2445,63888,2342)
'
'eee=$4207
'i=code("Q")
'poke eee,i
'eee=eee+1
'i=code("T")
'poke eee,i
'
'seed=0
'for eee=$4400 to $47FF
'  seed=smsrnd(seed)
'  poke eee,seed
'  next
'
'ex0=80:ey0=176
'
'eee=0
'ecsp=0:ecsq=0
'
'
'do
'poke $A600,255 '- watchdog? - it seems to work! thanks, Jim Bagley!!!!
'
'ej0=peek($A800) bxor $ff
'ej1=peek($A880) bxor $ff
'
'poke ($8400+(10*32)+6) bxor %0000001111100000,ej0
'poke ($8400+(10*32)+7) bxor %0000001111100000,ej1
'
'poke ($8400+(12*32)+8) bxor %0000001111100000,48+(ex0 mod 10)
'poke ($8400+(12*32)+7) bxor %0000001111100000,48+((int(ex0/10)) mod 10)
'poke ($8400+(12*32)+6) bxor %0000001111100000,48+((int(ex0/100)) mod 10)
'
'poke ($8400+(13*32)+8) bxor %0000001111100000,48+(ey0 mod 10)
'poke ($8400+(13*32)+7) bxor %0000001111100000,48+((int(ey0/10)) mod 10)
'poke ($8400+(13*32)+6) bxor %0000001111100000,48+((int(ey0/100)) mod 10)
'
'
'poke ($8400+(15*32)+8) bxor %0000001111100000,48+(ej0 mod 10)
'poke ($8400+(15*32)+7) bxor %0000001111100000,48+((int(ej0/10)) mod 10)
'poke ($8400+(15*32)+6) bxor %0000001111100000,48+((int(ej0/100)) mod 10)
'
'poke ($8400+(16*32)+8) bxor %0000001111100000,48+(ej1 mod 10)
'poke ($8400+(16*32)+7) bxor %0000001111100000,48+((int(ej1/10)) mod 10)
'poke ($8400+(16*32)+6) bxor %0000001111100000,48+((int(ej1/100)) mod 10)
'
'poke ($8400+(17*32)+8) bxor %0000001111100000,48+(ecsp mod 10)
'
'
